package com.taptech.doufu.ui.view.choice;

import android.content.Context;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;

import com.taptech.doufu.R;
import com.taptech.doufu.bean.choice.ChoiceTopicBean;
import com.taptech.doufu.bean.choice.NovelModel;
import com.taptech.doufu.ui.view.choice.adapter.ChoiceTopicGridAdapter;
import com.taptech.doufu.ui.view.choice.base.ChoiceTopicNovelBaseView;
import com.taptech.doufu.ui.view.topicview.MeasuredGridLayoutManager;

import java.util.List;

public class ChoiceTopicNormalView extends ChoiceTopicNovelBaseView {
    private Context context;
    private RecyclerView mRecyclerView;
    private ChoiceTopicGridAdapter adapter;
    private View layTop;

    public ChoiceTopicNormalView(Context context) {
        super(context);
    }

    public ChoiceTopicNormalView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public ChoiceTopicNormalView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public ChoiceTopicNormalView(Context context, ChoiceTopicBean bean) {
        this(context);
        View view = LayoutInflater.from(context).inflate(R.layout.topic_choice_normal_view, null);
        mRecyclerView = view.findViewById(R.id.mRecyclerView);
        layTop = view.findViewById(R.id.layTop);
        this.context = context;
        initTop(view,bean);
        layTop.setVisibility(GONE);
        setData(bean.getNovelList());
        addView(view);
    }


    public void setData(List<NovelModel> list) {
        adapter = new ChoiceTopicGridAdapter(context,list,eventData);
        MeasuredGridLayoutManager gridLayoutManager = new MeasuredGridLayoutManager(getContext(),4);
        gridLayoutManager.setScrollEnabled(false);
        mRecyclerView.setLayoutManager(gridLayoutManager);
        mRecyclerView.setAdapter(adapter);
    }

    @Override
    public void updateList(List<NovelModel> list) {
        setData(list);
    }
}
